<template>
	<view style="background-color: #F1F1F1;">
		<view class="bannerBox" style="">
			<view style="width: 60%;text-align: center;">
				<view style="color: #fff;font-size: 35upx;">白银市坤瑞恒建材有限公司</view>
				<view class="tags" style="">
					<view class="tag">专业</view>
					<view class="tag">精致</view>
					<view class="tag">服务</view>
					<view class="tag">稳定</view>
				</view>
			</view>
		</view>
		<!-- 公司简介 产品展示 公司新闻 图片新闻 -->
		<view class="function-block">
			<view class="tags">
				<view class="tag" @tap="goProfile()">
					<image class="img" src="../../static/img/1.png"></image>
					公司简介
				</view>
				<view class="tag" @tap="goProduct()">
					<image class="img" src="../../static/img/2.png"></image>
					产品展示
				</view>
				<view class="tag" @tap="goNews()">
					<image class="img" src="../../static/img/3.png"></image>
					公司新闻
				</view>
				<view class="tag" @tap="goPicNews()">
					<image class="img" src="../../static/img/4.png"></image>
					图片新闻
				</view>
			</view>
		</view>
		<!-- 视频展示 -->
		<view class="video">
			<view class="title">
				——&nbsp;&nbsp;视频展示&nbsp;&nbsp;——
			</view>
			<video
			src="http://bykrhwebset.oss-cn-hangzhou.aliyuncs.com/static/video/about.mp4"
			class="content"
			poster="http://jzkj02.oss-cn-hangzhou.aliyuncs.com/file/xW71600939317218.png"></video>
		</view>
		<!-- 产品展示 -->
		<view class="products">
			<view class="title">
				——&nbsp;&nbsp;产品展示&nbsp;&nbsp;——
			</view>
			<view class="content">
				<block v-for="(v, index) in product.list" :key="index">
					<view class="block" @tap="goProduct()">
						<image class="img" :src="v.img_url" mode="aspectFill"></image>
						<view style="padding: 20upx 0;">
							{{v.name}}
						</view>
					</view>
				</block>
			</view>
		</view>
		<!-- 公司新闻 -->
		<view class="news">
			<view class="title">
				——&nbsp;&nbsp;公司新闻&nbsp;&nbsp;——
			</view>
			<view class="content">
				<block v-for="(v, index) in news.list" :key="index">
					<view class="block flex" @tap="goNews()">
						<view class="img"><image class="img" :src="v.img_url" mode="scaleToFill"></image></view>
						<view class="text">
							<view class="text1">{{v.title}}</view>
							<view class="text2">{{v.create_time}}</view>
						</view>
					</view>
				</block>
			</view>
		</view>
		<!-- 图片新闻 -->
		<view class="picture-news">
			<view class="title">
				——&nbsp;&nbsp;图片新闻&nbsp;&nbsp;——
			</view>
			<scroll-view scroll-x="true" class="content">
				<block v-for="(v, index) in picNews.list" :key="index">
					<view class="scroll" @tap="goPicNews()">
						<view class="block">
							<image class="img" :src="v.img_url"></image>
							<view style="padding: 20upx 0;">{{v.title}}</view>
						</view>
					</view>
				</block>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				product: {
					pageNumber: 1,
					firstPage: true,
					lastPage: true,
					list: [],
				},
				news: {
					pageNumber: 1,
					firstPage: true,
					lastPage: true,
					list: [],
				},
				picNews: {
					pageNumber: 1,
					firstPage: true,
					lastPage: true,
					list: [],
				},
			};
		},
		methods:{
			getProduct(pageNumber){
				let self = this;
				uni.showLoading({title: '加载中',mask: true});
				this.config.post('/api/product/findPage', {
					pageNum: pageNumber?pageNumber:1,
				}).then(res=>{
					uni.hideLoading();
					if(res.data.code==='0'){
						self.product.pageNumber = res.data.page.pageNumber;
						self.product.firstPage = res.data.page.firstPage;
						self.product.lastPage = res.data.page.lastPage;
						self.product.list = res.data.page.list.slice(0,4);
					}else{
						uni.showToast({title: self.config.handleError(res.data),icon: 'none'});
					}
				})
			},
			getNews(pageNumber){
				let self = this;
				uni.showLoading({title: '加载中',mask: true});
				this.config.post('/api/news/findPage', {
					type: 2,
					pageNum: pageNumber?pageNumber:1,
				}).then(res=>{
					uni.hideLoading();
					if(res.data.code==='0'){
						self.news.pageNumber = res.data.page.pageNumber;
						self.news.firstPage = res.data.page.firstPage;
						self.news.lastPage = res.data.page.lastPage;
						self.news.list = res.data.page.list.slice(0,4);
					}else{
						uni.showToast({title: self.config.handleError(res.data),icon: 'none'});
					}
				})
			},
			getPicNews(pageNumber){
				let self = this;
				uni.showLoading({title: '加载中',mask: true});
				this.config.post('/api/news/findPage', {
					type: 1,
					pageNum: pageNumber?pageNumber:1,
				}).then(res=>{
					uni.hideLoading();
					if(res.data.code==='0'){
						self.picNews.pageNumber = res.data.page.pageNumber;
						self.picNews.firstPage = res.data.page.firstPage;
						self.picNews.lastPage = res.data.page.lastPage;
						self.picNews.list = res.data.page.list.slice(0,4);
					}else{
						uni.showToast({title: self.config.handleError(res.data),icon: 'none'});
					}
				})
			},
			goProduct(){
				uni.navigateTo({
					url: '/pages/main/products/products'
				})
			},
			goNews(){
				uni.navigateTo({
					url: '/pages/main/news/news'
				})
			},
			goPicNews(){
				uni.navigateTo({
					url: '/pages/main/news/picNews'
				})
			},
			goProfile(){
				uni.navigateTo({
					url: '/pages/main/company-profile/company-profile'
				})
			},
		},
		onShow() {
			if(this.product.list.length < 1){
				// console.log(this.product.list.length);
				// console.log('请求了');
				this.getProduct('1');
				this.getNews('1');
				this.getPicNews('1');
			}
		},
		mounted() {
			// this.config.getLoginInfo();
		}
	}
</script>

<style scoped lang="less">
	.bannerBox{
		width: 100%;
		height: 280upx;
		// background: url(http://jzkj02.oss-cn-hangzhou.aliyuncs.com/file/BES1600655749700.jpg);
		background: url(http://jzkj02.oss-cn-hangzhou.aliyuncs.com/file/p5R1616394212837.jpg);
		background-size: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		.tags{
			width: 100%;
			display: flex;
			justify-content: space-around;
			font-size: 25upx;
			color: #fff;
			margin-top: 50upx;
			.tag{
				width: 100upx;
				line-height: 40upx;
				border-radius: 30upx;
				background-color: rgba(0,0,0,0.1);
				text-align: center;
			}

		}
	}
	.function-block{
		width: 100%;
		height: 180upx;
		background-color: #fff;
		.tags{
			width: 100%;
			display: flex;
			justify-content: space-around;
			font-size: 25upx;
			color: #000;
			.tag{
				width: 100upx;
				line-height: 40upx;
				text-align: center;
				.img{
					margin-top: 20upx;
					width: 100upx;
					height: 100upx;
				}
			}
		}
	}
	.video{
		width: 100%;
		margin-top: 10upx;
		// background-color: #fff;
		text-align: center;
		.title{
			width: 100%;
			font-size: 25upx;
			font-weight: bold;
			color: #007aff;
			padding-top: 40upx;
		}
		.content{
			width: 96%;
			margin-top: 20upx;
			margin-bottom: 10upx;
			// margin-left: 15upx;
			// margin-right: 15upx;
		}
	}
	.products{
		width: 100%;
		margin-top: 10upx;
		// background-color: #fff;
		text-align: center;
		.title{
			width: 100%;
			font-size: 25upx;
			font-weight: bold;
			color: #007aff;
			padding-top: 20upx;
			margin-bottom: 40upx;
		}
		.content{
			width: 100%;
			display: inline-flex;
			justify-content: space-around;
			flex-wrap: wrap;
			margin-bottom: 10upx;
			padding: 0 10upx;
			box-sizing: border-box;
			.block{
				width: 45%;
				// height: 250upx;
				box-shadow: 0 0 10px 0 #ccc;
				border-radius: 10upx;
				font-size: 25upx;
				margin: 0 0 35upx 0;
				.img{
					width: 100%;
					height: 200upx;
					border-top-left-radius: 20upx;
					border-top-right-radius: 20upx;
				}
			}
		}
	}
	.news{
		width: 100%;
		margin-top: 10upx;
		// background-color: #fff;
		text-align: center;
		.title{
			width: 100%;
			font-size: 25upx;
			font-weight: bold;
			color: #007aff;
			padding-top: 20upx;
			margin-bottom: 20upx;
		}
		.content{
			width: 100%;
			display: flex;
			flex-direction: column;
			text-align: center;
			margin-bottom: 10upx;
			.block{
				margin: 0 3% 30upx 3%;
				border-radius: 10upx;
				overflow: hidden;
				box-shadow: 0 0 20px 0 #ccc;
				.img{
					width: 180upx;
					height: 150upx;
					margin-right: 10upx;
				}
				.text{
					padding: 20upx 10upx;font-size: 25upx;text-align: left;
					display: flex;flex-direction: column;
					justify-content: space-between;align-items: flex-start;
					.text1{
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}
					.text2{
						color: #888;
					}
				}
			}
		}
	}
	.picture-news{
		width: 100%;
		margin-top: 10upx;
		// background-color: #fff;
		text-align: center;
		.title{
			width: 100%;
			font-size: 25upx;
			font-weight: bold;
			color: #007aff;
			padding-top: 20upx;
			margin-bottom: 20upx;
		}
		.content{
			width: 100%;
			display: flex;
			overflow: hidden;
			white-space: nowrap;
			text-align: center;
			.scroll{
				width: 40%;
				height: 250upx;
				display: inline-block;
				box-shadow: 0 0 10px 0 #ccc;
				border-radius: 10upx;
				font-size: 25upx;
				margin: 10upx 0 20upx 2%;
				.block{
					width: 100%;
					height: 100%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					.img{
						width: 100%;
						border-top-left-radius: 8upx;
						border-top-right-radius: 8upx;
					}
				}
			}
			.scroll:last-child{
				margin: 10upx 2% 20upx 2%;
			}
		}
	}
</style>
